package com.scanner;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Point;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

@SuppressLint("NewApi")
public abstract class BaseTurnView extends View {
	Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	Path curvePath1 = null;
	Path curvePath2 = null;
	Point point1_draw;
	Point point2_draw;
	Point point3_draw;
	Point point4_draw;
	Point point5_draw;
	Point point6_draw;
	Point point7_draw;
	Point point8_draw;
	Point point9_draw;
	Point point10_draw;
	
	Point screenSize;
	
	//triangles consts
	final double arrowCenter = 0.5;
	final double arrowBelly = 0.1;
	final double arrowBaseThreshold = 0.7;
	final double arrowCentering = 0.2;
	final int arrowHeadLength = 60;
	
	protected boolean clearFlag = false;
	
	
	public BaseTurnView(Context context)
	{
		super(context);
		paint.setStyle(Style.STROKE);
		paint.setStrokeWidth(20);
	    paint.setARGB(120, 0, 250, 120);   
	    paint.setAntiAlias(true);
	    
	    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
	    Display display = wm.getDefaultDisplay();
	    screenSize = new Point();
	    display.getSize(screenSize);
	    
	    SetPoints();
	    
		setWillNotDraw(false);
		
	}
	
	abstract void SetPoints();
	
	@Override
	public void	onDraw(Canvas canvas)
	{
		if (!clearFlag)
		{
			if (curvePath1 == null || curvePath2 == null)
			{
				curvePath1 = new Path(); 
				curvePath1 = drawCurve(point1_draw,point2_draw,point3_draw);
				
				curvePath2 = new Path(); 
				curvePath2 = drawCurve(point4_draw,point5_draw,point6_draw);
			}
			canvas.drawPath(curvePath1, paint);
			canvas.drawPath(curvePath2, paint);
		}
	}
	
	private Path drawCurve(Point mPointa, Point mPointb, Point mPointc) {

	    Path curvePath = new Path();
	    curvePath.moveTo(mPointa.x, mPointa.y);
	    curvePath.quadTo(mPointb.x, mPointb.y, mPointc.x, mPointc.y);
	    return curvePath;  
	}
	
	public void ClearView()
	{
		clearFlag = true;
		this.invalidate();
		clearFlag = false;
	}

}
